let {
    system
} = require("./system_schema.js");
let {
    user
} = require("../login/sign_schma.js");
module.exports = {
    addSystem: function (req, res, err) {
        let reqData = req.body;
        let addressee = reqData.addressee;
        let core = reqData.core;
        let reply = reqData.reply.toLowerCase();
        if(core==1){
            reqData.sendUser = "情缘工作组";
        }
        if (addressee == "all") {
            //发送给所有用户
            user.find({}).then((userlist) => {
                userlist.forEach((item) => {
                    let user = item.user;
                    reqData.reply = reply == "yes" ? true : false;
                    reqData.addressee = user;
                    system.create(reqData);
                })
            })
        } else {
            reqData.reply = reply == "yes" ? true : false;
            // reqData.addressee = core;
            // console.log(reqData);
            system.create(reqData);
        }
        res.send(true);
    }
}